package com.ericom.webapp.action;

import java.util.List;

import com.ericom.model.ReturnGoodsOrderItem;
import com.ericom.service.GenericManager;

public class ReturnGoodsOrderItemAction extends BaseAction {
	private GenericManager<ReturnGoodsOrderItem, Long> returnGoodsOrderItemManager;
	private List returnGoodsOrderItems;
	private ReturnGoodsOrderItem returnGoodsOrderItem;
	private Long id;

	public ReturnGoodsOrderItem getReturnGoodsOrderItem() {
		return returnGoodsOrderItem;
	}

	public void setReturnGoodsOrderItem(
			ReturnGoodsOrderItem returnGoodsOrderItem) {
		this.returnGoodsOrderItem = returnGoodsOrderItem;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setReturnGoodsOrderItemManager(
			GenericManager<ReturnGoodsOrderItem, Long> returnGoodsOrderItemManager) {
		this.returnGoodsOrderItemManager = returnGoodsOrderItemManager;
	}

	public String list() {
		returnGoodsOrderItems = returnGoodsOrderItemManager.getAll();
		return SUCCESS;
	}

	public List getReturnGoodsOrderItems() {
		return returnGoodsOrderItems;
	}

	public String delete() {
		returnGoodsOrderItemManager.remove(returnGoodsOrderItem.getId());
		this.saveMessage(getText("returnGoodsOrderItem.deleted"));
		return this.SUCCESS;
	}

	public String edit() {
		if (id != null) {
			returnGoodsOrderItem = returnGoodsOrderItemManager.get(id);
		} else {
			returnGoodsOrderItem = new ReturnGoodsOrderItem();
		}
		return this.SUCCESS;
	}

	public String save() throws Exception {
		if (this.cancel != null) {
			return this.CANCEL;
		}
		if (this.delete != null) {
			return this.delete();
		}

		boolean isNew = (returnGoodsOrderItem.getId() == null);

		returnGoodsOrderItem = returnGoodsOrderItemManager
				.save(returnGoodsOrderItem);

		String key = (isNew) ? "returnGoodsOrderItem.added"
				: "returnGoodsOrderItem.updated";
		this.saveMessage(getText(key));

		if (!isNew) {
			return this.INPUT;
		} else {
			return this.SUCCESS;
		}
	}
}
